package com.oa.pm.controller;

import com.joneying.common.web.response.Resp;
import com.oa.core.exception.BusinessException;
import com.oa.core.exception.DataIsEmptyException;
import com.oa.pm.dto.DimissionManagementAddDTO;
import com.oa.pm.dto.DimissionManagementAuditDTO;
import com.oa.pm.dto.DimissionManagementListDTO;
import com.oa.pm.vo.DimissionManagementDetailsVO;
import com.oa.pm.vo.DimissionManagementListVO;
import com.oa.core.PageResult;
import com.oa.pm.service.IDimissionManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/dimissionManagement")
@Api(description = "离职管理表模块")
public class DimissionManagementController extends BaseController {

    private final IDimissionManagementService dimissionManagementService;

    @Autowired
    public DimissionManagementController(IDimissionManagementService dimissionManagementService) {
        this.dimissionManagementService = dimissionManagementService;
    }

    @GetMapping("/list")
    @CommonController
    @Description("查询所有")
    @ApiOperation(value = "记录列表")
    public Resp<PageResult<DimissionManagementListVO>> findDimissionManagementList(DimissionManagementListDTO dimissionManagementListDTO){
        dimissionManagementListDTO.setUserId("");
        return new Resp<PageResult<DimissionManagementListVO>>().success(dimissionManagementService.findDimissionManagementAuditList(dimissionManagementListDTO));
    }

    @GetMapping("/audit/list")
    @CommonController
    @Description("查询所有")
    @ApiOperation(value = "审核列表")
    public Resp<PageResult<DimissionManagementListVO>> findDimissionManagementAuditList(DimissionManagementListDTO dimissionManagementListDTO){
        dimissionManagementListDTO.setUserId(getLoginUserId());
        return new Resp<PageResult<DimissionManagementListVO>>().success(dimissionManagementService.findDimissionManagementAuditList(dimissionManagementListDTO));
    }

    @PostMapping("")
    @CommonController
    @Description("添加离职申请")
    @ApiOperation(value = "添加离职申请")
    public Resp add(@RequestBody DimissionManagementAddDTO dimissionManagementAddDTO) throws BusinessException, DataIsEmptyException {
        dimissionManagementAddDTO.setUserId(getLoginUserId());
        return dimissionManagementService.add(dimissionManagementAddDTO);
    }

    @GetMapping("/audit/{id}")
    @CommonController
    @Description("根据ID查询审核详情")
    @ApiOperation(value = "审核详情")
    public Resp<DimissionManagementDetailsVO> findDimissionManagementAudit(@ApiParam("ID") @PathVariable String id){
        return new Resp<DimissionManagementDetailsVO>().success(dimissionManagementService.findDimissionManagementAudit(id));
    }

    @PutMapping("/audit")
    @CommonController
    @Description("审核")
    @ApiOperation(value = "审核")
    public Resp audit(@RequestBody DimissionManagementAuditDTO dimissionManagementListDTO) throws DataIsEmptyException {
        return new Resp().success(dimissionManagementService.audit(dimissionManagementListDTO));
    }
}
